#ifndef __SBSESSION_HPP_
#define __SBSESSION_HPP_

#include <iostream>
#include <string>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>
#include "../common/network/Session.hpp"

    namespace network
    {

        namespace packet
        {
            class BasicPacket;
			class CancelOperation;
			class RequestGeneriks;
        }
		namespace buffer
		{
			class BasicBuffer;
		}

        class SBSessionManager;

        class SBServerSession :
        public boost::enable_shared_from_this<SBServerSession>,
        public Session
        {
        public:

            SBServerSession(boost::asio::io_service& _ioService, SBSessionManager& _manager, boost::uint16_t _sessionId);

            virtual ~SBServerSession();

            void start();

			virtual void on_packet(buffer::BasicBuffer& _packet);
			virtual void on_packet(packet::CancelOperation& _packet);
			virtual void on_packet(packet::RequestGeneriks& _packet);
        

            /**
             * Function called for the first receipt on the buffer
             */
            virtual void handle_read_first_packet(const boost::system::error_code& e, std::size_t bytes_transferred);



            /**
             * Function called when new data arrived on the buffer
             */
            virtual void handle_read(const boost::system::error_code& e, std::size_t bytes_transferred);


            /**
             * Function called after writing on the socket, we get the state
             */
            virtual void handle_write(const boost::system::error_code& e, std::size_t bytes_transferred);

        protected:

            enum session_state
            {
                _not_logged_,
                _user_logged_,
                _inter_server_logged_
            };

            /**
             * Reference on the manager
             */
            SBSessionManager& m_sessionManager;

            /**
             * IDSession
             */
            boost::uint16_t m_sessionId;

            /**
             * Session's state
             */
            session_state m_sessionState;

			bool m_stopRequesting;

            // Save info of a running login
            //login_data::login_info login_info_;


        };

        typedef boost::shared_ptr<SBServerSession> sb_session_ptr;


    } // // namespace network


#endif // __SBSESSION_HPP_
